package com.tools.acceleratecore.xlib.util;

import android.content.Context;
import android.os.Build;
import android.os.Process;

import java.lang.reflect.Method;

public class UtilEnv {
    public static int VALUE_INT_BUFFER_SIZE = 1024;
    public static String VALUE_STRING_CPU_ABI_ARMEABI = "armeabi";
    public static String VALUE_STRING_CPU_ABI_ARMEABIV7A = "armeabi-v7a";
    public static String VALUE_STRING_CPU_ABI_X86 = "x86";
    public static String VALUE_STRING_CPU_ABI_ARM64_V8A = "arm64-v8a";

    public static int getAndroidVersion() {
        return Build.VERSION.SDK_INT;
    }

    public static String getCpuABI() {
        return Build.CPU_ABI;
    }

    public static String getUserSerialNumber(Context context) {
        if (context == null) {
            return null;
        }
        Object userManager = context.getSystemService(Context.USER_SERVICE);
        if (userManager == null)
            return null;
        try {
            Method methodMyUserHandle = Process.class.getMethod(
                    "myUserHandle");
            Object objMyUserHandle = methodMyUserHandle.invoke(
                    Process.class);

            Method methodGetSerialNumberForUser = userManager.getClass()
                    .getMethod("getSerialNumberForUser", new Class[]{
                            objMyUserHandle.getClass()});
            long lUserSerial = ((Long) methodGetSerialNumberForUser.invoke(
                    userManager, new Object[]{objMyUserHandle})).longValue();

            return String.valueOf(lUserSerial);
        } catch (Exception e) {
            e.printStackTrace();
        }

        return null;
    }
}
